<!-- 新建样品里的客户选择组件 -->
<template>
	<div>
		<u-popup safe-area-inset-bottom v-model="show" mode="left">
			<customNavbar :title="title" @back="show = false"></customNavbar>
			<!-- 搜索区域 -->
			<div v-if="isEntity" style="position: fixed;width: 99%;background-color: #fff;z-index: 999;">
				<div style="margin-top: 10px;">
					<uni-search-bar style="color:#fff" :textColor="'#ccc'" @confirm="search"
						v-model="queryParam.Keyword" @clear="cancel" placeholder="请输入客户名称"
						@cancel="cancel"></uni-search-bar>
				</div>
			</div>


			<div class="outerBox" style="width:300px;padding-top:140rpx;">
				<scroll-view style="width: 100%;height: 100%;" scroll-y="true" @scrolltolower="lower">
					<div class="ckbxcli" @click="customerChoice(item)" v-for="(item, index) in data" :key="index">
						<div style="text-align: left;">
							<view style="display: flex;justify-content: space-between;">
								<view span="20">
									<span style="font-size: 14px;font-weight: bold">{{ item.cCusName }}</span>
								</view>
								<view>
									<!-- 暂时去掉  后续根据需求操作 -->
									<!-- 	<p>
										<uni-tag v-if="item.cCusType === -1" type="primary" :text="'备案中'" inverted></uni-tag>
										<uni-tag v-else-if="item.cCusType === 0" type="primary" :text="'正式'" inverted></uni-tag>
										<uni-tag v-else-if="item.cCusType === 1" type="primary" :text="'潜在'" inverted></uni-tag>
										<uni-tag v-else-if="item.cCusType === 2" type="primary" :text="'休眠'" inverted></uni-tag>
										<uni-tag v-else-if="item.cCusType === 3" type="primary" :text="'待转正'" inverted></uni-tag>
									</p> -->
								</view>
							</view>
							<u-row style="">
								<u-col>
									<p style="">客户编码：<span>{{ item.cCusCode }}</span></p>
								</u-col>
							</u-row>
							<u-row style="">
								<u-col span="11">
									<p style="">备案人：<span>{{ item.RealName }}</span></p>
								</u-col>
								<u-col span="13">
									<view style="">备案时间： <uni-dateformat
											:date="$moment(item.CreateTime).format('YYYY-MM-DD hh:mm:ss') "></uni-dateformat>
									</view>
								</u-col>
							</u-row>

						</div>
					</div>

					<div style="padding-bottom: 20px;">
						<LoadingMore :status="status" :contentText="contentText" :rows="data"></LoadingMore>
					</div>

					<div v-if="isSearchUser" class="search-none">
						<img src="../assets/search.png" alt="">
						<h4 style="color:#6C6C6C;margin-top:5px">客户检索</h4>
					</div>
				</scroll-view>
			</div>
		</u-popup>
	</div>
</template>

<script>
	// import PaginationCom from "@/components/PaginationCom.vue";
	import {
		// 获取客户列表数据
		CustomerInfoGetUionDataList,
		GetDataListForCustomerInfoRetrieval
	} from '@/api/interface.js'
	export default {
		props: {
			isAllData: {
				default: false,
				type: Boolean
			} // 是否查询全部数据
		},
		components: {
			// PaginationCom,
			// "van-pagination": Pagination,
		},
		data() {
			return {
				title: '选择客户',
				// 加载状态
				status: "loading",
				contentText: {
					contentdown: '轻轻上拉',
					contentrefresh: '努力加载中...',
					contentnomore: '实在没有了'
				},
				immediateCheck: false,
				loading: false,
				finished: false,
				selectedRowKeys: [],
				queryParam: {
					Condition: "cCusName",
					Keyword: ""
				},
				pagination: {
					current: 1,
					pageSize: 10,
					Total: 0,
				},
				entity: {},
				judgment: true,
				data: [],
				show: false,
				Id: "",
				PageRows: 20,
				isSearchUser: false,
				isEntity: true
			};
		},
		onLoad() {
			// 组件创建的时候初始默认检索提示
			this.isSearchUser = true
		},
		methods: {
			// 触底
			lower(e) {
				if (this.data.length >= this.pagination.Total) return
				// 上拉加载
				this.pagination.current++;
				this.getDataList()
			},
			onLoading() {
				this.loading = true; //防止第一页重复加载
				// 获取客户列表
				this.getDataList();
			},
			paginationchange(a) {
				// a:当前选中页码
				this.pagination.current = a;
				this.getDataList();
			},
			//返回
			onClickLeft() {
				this.show = false;
				// 返回时候显示检索提示
				this.isSearchUser = true
				//列表 数据重置
				this.queryParam.Keyword = ""
				this.data = []
			},
			close() {
				this.show = false;
			},
			// 取消
			cancel() {
				this.queryParam.Keyword = ""
				this.data = [];
				this.status = "noMore"
				this.isSearchUser = true
			},
			onSearch() {
				if (this.queryParam.Keyword) {
					this.search(this.queryParam.Keyword)
				} else {
					this.search
				}

			},
			//搜索
			search(value) {
				this.isSearchUser = false
				this.pagination.current = 1
				this.data = []
				this.status = "loading"
				this.getDataList();
			},
			customerChoice(item) {
				console.log(item);
				this.$emit("customerChoice", item);
				this.show = false;
			},
			// 获取客户列表
			getDataList() {
				console.log(this.isAllData)
				this.status = "loading"
				CustomerInfoGetUionDataList({
						PageIndex: this.pagination.current,
						PageRows: this.pagination.pageSize,
						SortField: "cCusCode",
						SortType: "desc",
						Search: this.queryParam,
						// ...this.filters
					})
					.then(resJson => {
						if (resJson.Success) {
							// 赋值总条数
							this.pagination.Total = resJson.Total;
							if (resJson.Data.length == 0 || resJson.Data == null) {
								this.status = "noMore"
								return
							}
							if (this.pagination.current == 1) {
								this.data = resJson.Data
							} else {
								// 有数据 赋值列表 加载状态结束
								this.data = this.data.concat(resJson.Data)
							}
							// 如果list长度大于等于总数据条数，数据全部加载完成
							if (this.data.length >= resJson.Total) {
								this.status = "noMore"
								return
							}

						} else {
							this.$errorToast(resJson.Msg);
							this.status = "noMore"
						}
					});
			},
			init() {
				this.show = true;
				this.cancel()
			},
			// 专门给openForm传递过来的entity使用
			setCustomNameArr() {
				this.status = "loading"

				CustomerInfoGetUionDataList({
						PageIndex: this.pagination.current,
						PageRows: this.pagination.pageSize,
						SortField: "cCusCode",
						SortType: "desc",
						Search: this.queryParam,
						// ...this.filters
					})
					.then(resJson => {
						if (resJson.Success) {
							// 赋值总条数
							this.pagination.Total = resJson.Total;
							if (resJson.Data.length == 0 || resJson.Data == null) {
								this.status = "noMore"
								return
							}
							// 有数据 赋值列表 加载状态结束
							this.data = this.data.concat(resJson.Data)
							this.isSearchUser = false
							// 如果list长度大于等于总数据条数，数据全部加载完成
							if (this.data.length >= resJson.Total) {
								this.status = "noMore"
								return
							}

						} else {
							this.$errorToast(resJson.Msg);
							this.status = "noMore"
						}
					});

			},
			openForm(entity) {
				console.log('传递过来的entityowuser', entity)
				if (entity) {
					console.log('走有entity的', this.isEntity)
					// 从报销单进去的不显示搜索栏
					if (entity.CustomId) {
						this.isEntity = false
						let CustomerName = entity.CustomerName.split(',')
						console.log('循环', CustomerName)
						CustomerName.forEach(item => {
							this.queryParam.Keyword = ""
							this.queryParam.Keyword = item
							this.setCustomNameArr()
						})
					} else {
						this.isEntity = true
					}
				}
				console.log('走没有entity的', this.isEntity)
				// 搜索调价初始化
				this.queryParam.Keyword = ""
				this.init();
			}
		}
	};
</script>

<style scoped lang="less">
	::v-deep.uni-navbar {
		.uni-navbar__content {
			border-bottom-color: #fff !important;
		}
	}

	.search-none {
		height: 70%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.outerBox {
		/* 	height: calc(100vh - 120px);
		padding-bottom: 50px;
		box-sizing: border-box;
		overflow: auto; */
		/* #ifdef H5 */
		height: calc(100vh - 50px);
		/* #endif */
		/* #ifdef APP */
		height: calc(100vh - 200px);
		/* #endif */
	}

	.ckbxcli {
		border: 1px solid Gainsboro;
		width: 95%;
		text-align: center;
		margin-left: 2%;
		margin-top: 10px;
		box-sizing: border-box;
		padding: 20rpx;
		/* 	padding-right: 0px;
		padding-left: 0px;
		padding-bottom: 2px; */
		cursor: pointer;
		/* padding-top: 6px; */
		list-style-type: none;
		display: inline-block;
	}

	.ul {
		/* margin-top: 20px; */
	}

	.nav {
		position: fixed !important;
		width: 100%;
	}
</style>